#!/bin/sh -eu

. "$(dirname "$0")/common.sh"

test_cleanup() {
    if mountpoint -q "$scratch_dir/mnt"; then
	umount "$scratch_dir/mnt"
    fi
}

assert_kconfig CONFIG_XFS_FS

truncate -s 1G "$scratch_dir/xfs.img"
mkfs.xfs "$scratch_dir/xfs.img"

curl -o "$scratch_dir/setattr.c" \
     "https://bugzilla.kernel.org/attachment.cgi?id=274733"
cc -Wall -Wextra -O2 "$scratch_dir/setattr.c" -o "$scratch_dir/setattr"

mkdir "$scratch_dir/mnt"
mount -o loop -t xfs "$scratch_dir/xfs.img" "$scratch_dir/mnt"

"$scratch_dir/setattr" "$scratch_dir/mnt/hello"
value="$(getfattr -n user.world --absolute-names --only-values  "$scratch_dir/mnt/hello")"
test "${#value}" -eq 2048

assert_untainted
